<template>
	<view>
		<view class="tab">
			<view class="tabItem" :class="{'tabItem_active':tabIndex == index}" v-for="(item,index) in tabList"
				:key="index" @tap="switchTab(index)">{{item}}</view>
		</view>
		<view class="none" v-if="isPage">没有内容</view>
		<view class="list" v-else>
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="itemTop">
					<view>{{item.title}}</view><text @click="edit(item)">编辑</text>
				</view>
				<view class="itemReason">退回原因：内容涉及{{item.set_name}}，请修正后发布</view>
				<view class="itemTip">详情图片：<span v-if="!item.visit_path">无</span></view>
				<view class="itemImage" v-if="item.image && item.image.length > 0">
					<image :src="imgItem" v-for="(imgItem,imgIndex) in item.image" :key="imgIndex"></image>
				</view>
				<view class="itemTime">审核时间：{{item.time}}</view>
			</view>
			<uni-load-more v-if="list.length >= 6" :status="status" :content-text="contentText" />
		</view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import util from '@/common/util.js';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				tabIndex: 0, //选项卡索引
				tabList: ['文章', '视频'], //选项卡列表
				page: 1,
				reload: true,
				isPage: false, //是否为空列表
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多',
					contentnot: "没数据"
				},
				list: [], //列表
			}
		},
		onPullDownRefresh() {
			this.page = 1;
			this.reload = true;
			this.isPage = false;
			this.list = [];
			this.getList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.status = 'loading';
			this.page = this.page + 1;
			var _this = this;
			setTimeout(function() {
				_this.getList();
			}, 500);
		},
		onLoad() {
			this.getList();
		},
		methods: {
			// 文章
			getList() {
				let arrList = [];
				var url = 'user/article.lists/reportlist'
				if (this.tabIndex == 1) {
					url = 'user/video.lists/reportlist';
				}
				this.$api.apiPost(url, {
					page: this.page,
					pagesize: 8
				}).then(res => {
					if (res.data.code == 200) {
						var list = res.data.data.data;
						list.forEach((item) => {
							item['time'] = util.getLeftTime(item.creat_time);
							if (item.visit_path) {
								item['image'] = item.visit_path.split(',');
							}
						})
						this.list = this.reload ? list : this.list.concat(list);
						this.reload = false;
						this.status = 'more';
					} else {
						if (this.reload) {
							this.list = [];
							this.isPage = true;
						} else {
							this.status = 'noMore';
						}
					}
				})
			},
			// 切换选项卡
			switchTab(index) {
				if (this.tabIndex != index) {
					this.list = [];
					this.tabIndex = index;
					this.getList();
				}
			},
			// 编辑
			edit(item) {
				if (this.tabIndex == 0) {
					uni.navigateTo({
						url: '/pages/articleModule/newarticle-release?type=edit&article_id=' + item.article_id
					})
				} else {
					// 获取黑名单列表
					let userBlackList = [];
					this.$api.apiPost('user/video.User/UserBlackList').then(res => {
						if (res.data.code == 200) {
							userBlackList = res.data.data.data;
						}
						this.$api.apiPost('user/video.Lists/VideoListByOne', {
							video_id: item.video_id
						}).then(res => {
							if (res.data.code == 200) {
								var list = res.data.data.data;
								list.forEach((v, i) => {
									v.black_state = false
									if (userBlackList.length > 0) {
										userBlackList.forEach(v1 => {
											if (v.user_id == v1.user_id) {
												v.black_state = true
											}
										})
									}
								})
								this.$forceUpdate();
								uni.navigateTo({
									url: '/pages/school/release?type=edit&item=' +
										encodeURIComponent(JSON.stringify(list[0]))
								})
							} else {
								uni.showToast({
									title: res.data.msg,
									icon: 'none'
								})
							}
						})
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #FAFAFA;
	}

	.tab {
		background: #FFFFFF;
		box-shadow: 0px 4upx 8upx rgba(0, 0, 0, 0.12);
		display: flex;
		justify-content: space-around;
		align-items: center;
		white-space: nowrap;
		overflow: auto;
		position: fixed;
		left: 0;
		width: 100%;
		height: 100upx;
		z-index: 9;
		/* #ifdef H5 */
		top: 88upx;
		/* #endif */
		/* #ifndef H5 */
		top: 0;
		/* #endif */

		.tabItem {
			color: #999999;
			font-size: 30upx;
			text-align: center;
			position: relative;
		}

		.tabItem_active {
			color: #333333;
		}

		.tabItem_active:before {
			position: absolute;
			content: '';
			height: 8upx;
			bottom: 0;
			left: 0;
			right: 0;
			margin: auto;
			background: #00D5A2;
			border-radius: 4upx;
		}
	}

	.none {
		color: #333333;
		font-size: 30upx;
		margin-top: 500upx;
		width: 100%;
		text-align: center;
	}

	.list {
		padding: 130upx 0;
	}

	.item {
		padding: 40upx 30upx;
		margin-bottom: 30upx;
		width: calc(100% - 60upx);
		background-color: #FFFFFF;

		.itemTop {
			display: flex;
			align-items: center;
			justify-content: space-between;

			view {
				font-size: 30upx;
			}

			view:first-child {
				width: 85%;
				color: #333333;
				font-weight: 500;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			text {
				color: #C0C4CC;
			}
		}

		.itemReason {
			color: #333333;
			font-size: 30upx;
			margin: 30upx 0 20upx;
		}

		.itemTip {
			color: #333333;
			font-size: 30upx;
			margin-bottom: 20upx;
			white-space: nowrap;
		}

		.itemImage {
			display: flex;
			align-items: center;
			flex-wrap: wrap;

			image {
				width: 200upx;
				height: 200upx;
				border-radius: 10upx;
				margin-right: 40upx;
				margin-bottom: 20upx;
			}

			image:nth-child(3n) {
				margin-right: 0;
			}
		}

		.itemTime {
			color: #C0C4CC;
			font-size: 26upx;
		}
	}
</style>